<?php
defined( 'BASEPATH' ) or exit( 'No direct script access allowed' );
class Menu_model extends MY_Model
{
    function get($uris)
    {
        if (! is_array( $uris ) || empty( $uris ))
        {
            return array ();
        }
        $this->_db->select( $this->_table, '`id`,`fid`,`name`,`target`,`uri`,`icon`' );
        $this->_db->where( '(`fid`=0 or `uri` in(?)) and `enable`=1 and `deleted`=0', $uris );
        $this->_db->order( '`fid`,`sort` desc' );
        return $this->_db->fetch_all();
    }
    function get_shortcut()
    {
        $this->_db->select( $this->_table, '`id`,`name`,`target`,`uri`,`shortcut_icon`' );
        $this->_db->where( '`is_shortcut`=1 and `fid`<>0 and `enable`=1 and `deleted`=0' );
        $this->_db->order( '`shortcut_sort` desc' );
        return $this->_db->fetch_all();
    }
    function get_submenus()
    {
        $sql = "SELECT b.`id`,b.`uri`,CONCAT(a.`name`,'/',b.`name`) AS `description` FROM `_{$this->_table}` AS a JOIN  `_{$this->_table}` AS b ON a.id=b.fid AND b.`enable`=1 AND b.`deleted`=0 ORDER BY b.`fid`,b.`sort` DESC";
        $this->_db->sql( $sql );
        return $this->_db->fetch_all();
    }
}